package com.example.zwlyz.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.zwlyz.R;
import com.example.zwlyz.models.Account;

import java.util.List;

public class AccountListAdapter extends BaseAdapter {
    private Context context;
    private List<Account> accounts;
    private OnItemClickListener listener;
    private OnItemLongClickListener longClickListener;

    public AccountListAdapter(Context context, List<Account> accounts) {
        this.context = context;
        this.accounts = accounts;
    }

    @Override
    public int getCount() {
        return accounts.size();
    }

    @Override
    public Object getItem(int position) {
        return accounts.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context)
                    .inflate(R.layout.item_account, parent, false);
        }
        TextView usernameTextView = convertView.findViewById(R.id.usernameTextView);
        usernameTextView.setText(accounts.get(position).getUsername());
        return convertView;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }

    public interface OnItemLongClickListener {
        boolean onItemLongClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    public void setOnItemLongClickListener(OnItemLongClickListener listener) {
        this.longClickListener = listener;
    }
}